/*  Copyright (C) Microsoft Corporation, 1997.  All rights reserved.

  This source code is intended only as a supplement to Microsoft
  Development Tools and/or on-line documentation.  See these other
  materials for detailed information regarding Microsoft code samples.

*/
//---------------------------------------------------------------------------
// StatBar.cpp - Implementation of helper Status Bar class.
//

#include <tchar.h>
#include "StatBar.h"

#undef THIS_FILE
static TCHAR THIS_FILE[] = __FILE__;


//---------------------------------------------------------------------------
// Implementation of Simple Status Bar Helper Class
//---------------------------------------------------------------------------
/***
* Create
* 
* Parameters:
*	hwndParent - [IN] The parent of this window. Required.
*
* Create the status bar.
**************************************************************************/
HRESULT CStatusBar::Create(HWND hwndParent)
{
	//ASSERT(hwndParent);
	if (!hwndParent)
	{
		return E_INVALIDARG;
	}

	m_hwndStatus = CreateStatusWindow(
							WS_CHILD | WS_BORDER | WS_VISIBLE, 
							_T(""), 
							hwndParent, 
							ID_STATUSBAR);

	if (!m_hwndStatus)
	{
		return E_FAIL;
	}

		// Only support simple text mode
	SendMessage(m_hwndStatus, SB_SETPARTS, N_SBAR_PARTS, (LPARAM)m_aWidths);

	// Default status
	SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)_T("READY"));

	// Save the height of the status bar
	RECT rect;
	GetClientRect(m_hwndStatus, &rect);
	m_iHeight = rect.bottom;
	
	GetClientRect(hwndParent, &rect);
	this->OnSize(rect.right-rect.left, rect.bottom-rect.top);

	return NOERROR;
}


/***
* OnSize
* 
* Parameters:
*	nWidth	- [IN] width of frame window
*	nHeight	- [IN] height of frame window
*
* Handle sizing of the status bar.
**************************************************************************/
void CStatusBar::OnSize(int iWidth, int iHeight)
{
	MoveWindow(m_hwndStatus, 0, iHeight - m_iHeight, iWidth, m_iHeight, TRUE);

	// Set the right edge of each pane
	m_aWidths[SBAR_PART_STATUS] = (iWidth / 2); // Use 50%
	m_aWidths[SBAR_PART_PROGRESS] = -1; // iWidth - m_aWidths[SBAR_PART_STATUS];
	//m_aWidths[SBAR_PART_PROJMODE] = -1;		// Right edge extends to right side

	SendMessage(m_hwndStatus, SB_SETPARTS, N_SBAR_PARTS, (LPARAM)m_aWidths);
}

